package com.company.jdk.methodRef;

import java.util.Arrays;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author yingfing
 * @create 2020--10--03 22:32
 * @describe
 */
public class TestMethodRef {
    public static void main(String[] args) {
        // 方法引用
        // 实例对象 :: 实例方法
        // 类名 :: 静态方法
        // 类名 :: 实例方法
        Arrays.asList(1, 21, 22, 3, 2, 4, 5, 5, 6, 667, 9, 98).stream()
//                .forEach(x-> System.out.println(x));
                .forEach(System.out::println); // x -> null
//        public final static PrintStream out = null;

        Consumer toString = Object::toString;
//        (new Object()) -> (new Object()).toString();

        Dog dog = new Dog("小白");
        Supplier<String> name = dog::getName;
        Supplier<String> name1 = () -> "小编";

        Function<String, Dog> dogObj = Dog::new;// String -> Dog
        Function<String, Dog> dogObj1 = (nm) -> new Dog(nm);

        BiFunction<Dog, String, Dog> printDog = Dog::printDog;

        Consumer<String> print = dog::print; // x-? null
        Consumer<String> print1 = prefix -> System.out.println(prefix);

    }

}

class Dog {
    String name;

    public Dog(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Dog printDog(String name) {
        return new Dog(name);
    }

    public void print(String prefix) {
        System.out.println(prefix);
    }
}